const express = require('express')

const app = express()

app.use(express.static('public'))

// 三部分 /请求方式 / 请求路径 / 回调函数

// 注册路由
app.get('/index',(req,res)=>{

    const {a,b} = req.query

    console.log("query参数",a,b);

    res.send('get 返回数据')  // send 有Concent-Type 功能
    

})
const allUsers = [
    {id:1,name:'tom',age:1},
    {id:2,name:'tom1',age:2},
    {id:3,name:'tom2',age:3},
]

app.get('/user/:id',(req,res)=>{
    const {id} = req.params

    const user = allUsers.find(user=>user.id === +id)

    res.send(user)
})


app.post('/index',(req,res)=>{


    console.log('body参数',req.body);
    res.send('post 返回数据') 
})






app.listen("3007",()=>{
    console.log('启动服务成功','http://localhost:3007');
})